using System;
using System.Collections.Generic;
using System.Text;

using Imagination.Collisions;

namespace Imagination.Partitioning
{
    public class SimplePartitioner : Partitioner
    {
        private SimpleZone zone;

        public SimplePartitioner(): base()
        {
            zone = new SimpleZone();
        }

        public Zone Zone
        {
            get { return zone; }
        }

        public override void CheckCollisions(Imagination.Collisions.CollisionDetector detector)
        {
			Thing thing1, thing2;
			Collision collision;
			
			for (int i = 0; i < zone.Things.Count - 1; i++)
			{
				thing1 = zone.Things[i];
				for (int j = i + 1; j < zone.Things.Count; j++)
				{
					thing2 = zone.Things[j];
					collision = detector.DetectCollision(thing1, thing2);
					if (collision != null)
					{
						thing1.RespondToCollision(collision);
						thing2.RespondToCollision(collision);
					}
				}
			}
		}

        public override void Clear()
        {
            zone.Things.Clear();
        }

        public override void CheckPartitioning(Thing thing)
        {
            if(thing.Zone == null)
            zone.AddThing(thing);
        }

        public override List<Zone> GetVisibleZones(Imagination.Display.Camera camera)
        {
            throw new Exception("The method or operation is not implemented.");
        }


        public override string ToString()
        {
            return String.Format("SimplePartitioningService: ({0})", zone.Things.Count);
        }
    }
}
